/*
 * Copyright 2016-2021 Pnoker. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xj.driver.mqtt.service.impl;

import com.xj.common.bean.constant.Common;
import com.xj.common.bean.em.ControlStateEm;
import com.xj.common.model.ControlInfo;
import com.xj.common.sdk.bean.driver.DriverContext;
import com.xj.common.sdk.service.ControlService;
import com.xj.common.sdk.service.DriverService;
import com.xj.driver.mqtt.bean.MqttHeaderB;
import com.xj.driver.mqtt.service.BusinessService;
import com.xj.driver.mqtt.util.MqttUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;


/**
 * @author pnoker
 */
@Slf4j
@Service
public class BusinessServiceImpl implements BusinessService {

    @Resource
    private ControlService controlService;

    //暂不实现，后续完善
    @Override
    public String createOrder(String userId, int orderTime, String chargeDevSn) {
        //记录订单
        //生成订单编号
        UUID id = UUID.randomUUID();




        return id.toString();
    }

    @Override
    public Long startChargeDev(String userId, int orderTime, String chargeDevSn,String open) {

        String sendBody = "{\"header\":{\"version\":\"V1.0\",\"timestamp\":\"2022-04-14\",\"index\":1,\"function\":\"remoteChargeStartReq\",\"reason\":3},\"dataBody\":{ \"chargeTime\":"+orderTime+", \"ctrlType\":"+open+", \"chargeDevNo\":\"00001\"}}";

        return controlService.snedCtl(sendBody,null,chargeDevSn,userId);


    }

    @Override
    public boolean updateOrder(String orderId, String userId, int orderTime, String chargeDevSn) {
        return false;
    }

    @Override
    public String getChargeState(String deviceid) {
        return null;
    }
}
